package com.example.book.mapper;

import com.example.book.model.BookInfo;
import com.example.book.model.PageRequest;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BookInfoMapper {
    @Insert("insert into book_info(book_name,author,count,price,publish,`status`)"+
            "values (#{bookName},#{author},#{count},#{price},#{publish},#{status})")
    Integer insertBook(BookInfo bookInfo);

    //count用于统计条数，比如数据库有24调数据就会显示24
    @Select("select count(1) from book_info where status !=0 ")
    Integer count();

    //当前页的记录,offset是起始位置，limit是查询的记录数
    @Select("select * from book_info where status !=0 order by id limit #{offset},#{pageSize}")
    List<BookInfo> queryBookByPage(PageRequest pageRequest);

    @Select("select * from book_info where id = #{bookId}")
    BookInfo queryBookById(Integer bookId);

    Integer updateBook(BookInfo bookInfo);

    void batchDeleteBook(List<Integer> ids);

}
